package com.eunion.web.cms.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.eunion.web.cms.entity.ScoreRank;
import com.eunion.web.cms.entity.spec.ScoreRankSpec;
import com.eunion.web.cms.repository.ScoreRankRepository;
import com.eunion.web.cms.service.ScoreRankService;
import com.eunion.web.common.base.BaseRepository;
import com.eunion.web.common.base.impl.BaseServiceImpl;

@Service(value = "scoreRankService")
@Transactional
public class ScoreRankServiceImpl extends BaseServiceImpl<ScoreRank, Long> implements ScoreRankService {

    private final Logger log = LoggerFactory.getLogger(ScoreRankServiceImpl.class);

    @Autowired
    private ScoreRankRepository scoreRankRepository;

    @Override
    public BaseRepository<ScoreRank, Long> geBaseRepository() {
        return scoreRankRepository;
    }

    @Override
    public Map<String, String> getScoreRankMap(ScoreRank query) {
        List<ScoreRank> list = scoreRankRepository.findAll(ScoreRankSpec.build(query));
        Map<String, String> map = null;
        if (list != null && list.size() > 0) {
            map = new HashMap<>();
            for (ScoreRank cur : list) {
                map.put(cur.getScore() + "", cur.getRank());
            }
        }
        return map;
    }

}
